﻿using System.Collections.Generic;
using System.IO;
using System.Net;
using LuaInterface;
using UnityEngine;

namespace Assets.Scripts.Game.Manager
{
    /**
     * 管理了所有的luaconfig数据 
     * 
     */
    
    public class LuaConfigMgr
    {
        private static readonly LuaConfigMgr mgr = new LuaConfigMgr();
        public static LuaConfigMgr Instance()
        {
            return mgr;
        }


        private Dictionary<string, LuaTable> findPool;

        public void Init()
        {
            findPool = new Dictionary<string, LuaTable>();

            //加载所有的luaconfig
            ioo.gameManager.uluaMgr.DoFile("config/CGLobal");
            LuaTable configTable = ioo.gameManager.uluaMgr.GetLuaTable("globalConfig");
            for (int i = 0; i < configTable.Count; i++)
            {
                string s = configTable[i+1] as string;
                
                object ret = ioo.gameManager.uluaMgr.DoFile("config/" + s);
 
                LuaTable tempLuaTable = ioo.gameManager.uluaMgr.GetLuaTable(s);
                if (tempLuaTable != null)
                {
                    findPool.Add(s, tempLuaTable);    
                }
                else
                {
                    Debug.Log("cant find lua table :"+s);
                }
            }

        }

        public LuaTable LoadGameObjectFromAssetBundleByName(string name)
        {
            LuaTable ret = null;
            if (findPool.TryGetValue(name,out ret))
            {
                return ret;
            }
            
            return null;            
        }

    }
}
